import { Component, OnInit, Input } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd/message';
import { FansTableModalService } from './fans-table-modal.service';

@Component({
  selector: 'fans-table-modal',
  templateUrl: './fans-table-modal.component.html',
  styleUrls: ['./fans-table-modal.component.scss']
})
export class FansTableModalComponent implements OnInit {
  @Input() userId: any;

  isFansVisible: boolean = false;

  fansTableParams: any = {
    tableLoading: false,
    page: 1,
    pageSize: 10,
    total: 0
  };
  fansTableData: any = [];

  constructor(
    private message: NzMessageService,
    private services: FansTableModalService
  ) { }

  ngOnInit(): void {
  }

  async loadFansTable() {
    let params = {
      id: this.userId,
      page: this.fansTableParams.page,
      pageSize: this.fansTableParams.pageSize
    }
    this.fansTableParams.tableLoading = true;
    const res: any = await this.services.getFansListData(params);
    this.fansTableParams.tableLoading = false;

    if (res.code == 0) {
      const { list, total } = res.data || {};
      this.fansTableData = list || [];
      this.fansTableParams.total = total || 0;
    } else {
      this.message.error(res.message);
    }
  }
    
  // 当前页码改变时的回调函数
  fansPageIndexChange(index: number) {
    this.fansTableParams.page = index;
    this.loadFansTable();
  }
  // 页数改变时的回调函数
  fansPageSizeChange(sizeNum: number) {
    this.fansTableParams.pageSize = sizeNum;
    this.loadFansTable();
  }
}
